var t = require("../../A4730AC3A71FB5DFC21562C4223CA4D1.js"), e = getApp(), a = require("../../C6EFF1F4A71FB5DFA08999F3BD3CA4D1.js").navBack, n = require("../../0BACB9C3A71FB5DF6DCAD1C4BE4CA4D1.js");

Page({
    data: {
        phoneNumber: "",
        mobileSalt: "",
        remainSecond: 0,
        statusBarHeight: e.globalData.statusBarHeight,
        titleBarHeight: e.globalData.titleBarHeight,
        sessionId: ""
    },
    onLoad: function(t) {
        this.setData({
            phoneNumber: t.phoneNumber,
            sessionId: t.sessionId
        });
    },
    onReady: function() {
        this.resendMobilSalt();
    },
    bindMobileSalt: function(t) {
        this.setData({
            mobileSalt: t.detail.value
        });
    },
    countdownSeconds: function() {
        var t = this, e = this.data.remainSecond;
        if (0 === e) return this.timeId && clearTimeout(this.timeId), void this.setData({
            remainSecond: 0
        });
        this.timeId = setTimeout(function() {
            t.setData({
                remainSecond: e - 1
            }, function() {
                t.countdownSeconds();
            });
        }, 1e3);
    },
    resendMobilSalt: function() {
        var e = this;
        this.data.remainSecond > 0 || (wx.showLoading({
            mask: !0
        }), t.post("/v2/sms/send", {
            type: 0,
            telephone: this.data.phoneNumber
        }).then(function(t) {
            wx.hideLoading(), 1001 === t.data.code && (wx.showToast({
                title: t.data.msg,
                icon: "success",
                duration: 1500
            }), e.setData({
                fillPhoneNumber: !0,
                remainSecond: 60
            }), e.countdownSeconds());
        }).catch(function() {
            wx.hideLoading();
        }));
    },
    goback: function() {
        a();
    },
    tapButton2: function() {
        wx.redirectTo({
            url: "/pages/register/index"
        });
    },
    tapButton: function() {
        var a = this.data.mobileSalt;
        if (0 !== a.length) {
            wx.showLoading({
                mask: !0
            });
            var i = n._cb;
            t.post("/v2/login", {
                auth_type: 4,
                telephone: this.data.phoneNumber,
                verify_code: a,
                jpush_registration_id: "",
                session_id: this.data.sessionId
            }).then(function(t) {
                if (wx.hideLoading(), 1001 === t.data.code) {
                    var a = t.data.response.data;
                    try {
                        wx.setStorageSync("user", a);
                    } catch (t) {}
                    e.globalData.isLogin = !0, e.globalData.authToken = a.user_token, e.globalData.user = a, 
                    wx.navigateBack({
                        delta: 1,
                        complete: function() {
                            "function" == typeof i && (i(1001), n._cb = null);
                        }
                    });
                } else "function" == typeof i && (i(1006), n._cb = null);
            }).catch(function() {
                "function" == typeof i && (i(1006), n._cb = null), wx.hideLoading();
            });
        } else wx.showToast({
            title: "请输入验证码！",
            icon: "none"
        });
    }
});